/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-08-22 09:12:46
 * @LastEditors: swc
 * @LastEditTime: 2024-06-16 07:31:32
 */
import { N_oSetupPanel } from '../types';
import { T_compConf } from './compConf';

export class T_setup extends T_compConf {
  public configStore!: {
    all: any;
    stored: any;
  };

  public layout!: {
    list: any;
    current: any;
  };

  public component!: {
    current: any;
    list: Array<
      N_oSetupPanel.N_comps.I_compItem<N_oSetupPanel.N_comps.I_compConfs>
    >;
  };

  public cell!: {
    id: string | undefined;
    structure: any;
    list: string[];
  };

  public stored!: {
    m2o: {
      field: string;
      value: any;
    }[];
  };

  public layouts = [];

  constructor(p: N_oSetupPanel.oSetupPanel) {
    super(p);
    this.init();
  }

  public init() {
    this.component = {
      current: null,
      list: this.getComponentList()
    };
    this.cell = {
      id: undefined,
      structure: {},
      list: []
    };
    this.configStore = {
      all: {},
      stored: []
    };
    this.stored = {
      m2o: []
    };
  }

  public clear(stored: boolean = true) {
    this.component = {
      current: null,
      list: this.getComponentList()
    };
    this.cell = {
      id: undefined,
      structure: {},
      list: []
    };
    this.stored = {
      m2o: []
    };
    this.configStore.all = {};
    if (stored) this.configStore.stored = [];
  }

  public getConfigStroeAttrOfAll(cellID?: string): any {
    return cellID ? this.configStore.all[cellID] : this.configStore.all;
  }
}
